package login;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-05-31
 * Time: 12:29
 */
public class Test {
    public static void login(User user) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的用户名:");
        String name = scanner.nextLine();
        System.out.println("请输入您的密码:");
        String password = scanner.nextLine();
        try {
            if (!name.equals(user.name)) {
                throw new UserNameException("用户名输入错误！");
            }
            if(!password.equals(user.password)) {
                throw new PasswordException("密码输入错误！");
            }
        }catch (UserNameException userNameException) {
            userNameException.printStackTrace();
            return;
        }catch (PasswordException passwordException) {
            passwordException.printStackTrace();
            return;
        }finally {
            scanner.close();
        }
        System.out.println("登录成功！");
    }
    public static void main(String[] args) {
        User user = new User("dings","801219");
        login(user);
    }
}
